﻿[assembly: System.Web.UI.TagPrefix("GSC.WebControls", "GSC")]
namespace GSC.WebControls
{
    using System;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.Design.WebControls;
    using System.Drawing.Design;
    using System.Drawing;
    using System.Web.UI.Design;
    using System.ComponentModel;
    using System.Security.Permissions;
    using System.Collections.Generic;
    using ComponentModel.Design;
    /// <summary>
    /// 左边垂直按钮菜单控件。
    /// </summary>
    /// <remarks>左边垂直按钮菜单控件。</remarks>
    [ToolboxItemFilter("GSC.WebControls", ToolboxItemFilterType.Custom)]
    [ToolboxData("<{0}:BackgroundCenterLeftButtonControl runat=server width=150px></{0}:BackgroundCenterLeftButtonControl>")]
    [SRDescription("Manage_CenterLeftButton", typeof(Properties.Resources))]
    [Designer(typeof(BackgroundCenterLeftButtonControlDesigner))]
    [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
    [AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)]
    [PersistChildren(false)]
    //[ParseChildren(true, "Buttons")]
    public class BackgroundCenterLeftButtonControl : DataBoundControl, INamingContainer, IPostBackEventHandler, ICompositeControlDesignerAccessor, IAsyncControlIDsExtender
    {
        #region IAsyncControlIDsExtender
        /// <summary>
        /// 
        /// </summary>
        List<string> IAsyncControlIDsExtender.ControlIDs
        {
            get
            {
                List<string> ids = new List<string>();
                //if (this.AutomaticLoadControl)
                //{
                    foreach (BackgroundCenterLeftMenuButtonControl citem in this.Buttons)
                    {
                        //string asxc = citem.Ascx;
                        //if (asxc != string.Empty && asxc.EndsWith(".ascx", StringComparison.InvariantCultureIgnoreCase))
                        //{
                            ids.Add(citem.Button.ClientID);
                        //}
                    }
                //}
                return ids;
            }
        }
        #endregion
        #region ICompositeControlDesignerAccessor
        void ICompositeControlDesignerAccessor.RecreateChildControls()
        {
            base.ChildControlsCreated = false;
            EnsureChildControls();
        }
        #endregion
        #region IPostBackEventHandler
        /// <summary>
        /// 客户端pos事件处理
        /// </summary>
        /// <param name="eventArgument"></param>
        void IPostBackEventHandler.RaisePostBackEvent(string eventArgument)
        {
            //转换客户端递交事件内容
            string[] Argument = eventArgument.Split(new Char[] { '&' });
            int n = 0;
            int cn = Convert.ToInt32(Argument[1]);
            if (Argument[0] == "Button")
            {
                BackgroundCenterLeftMenuButtonControl button = null;
                foreach (BackgroundCenterLeftMenuButtonControl citem in this.Buttons)
                {
                    if (cn == n)
                    {
                        button = citem;
                        if (!button.IsSelected)
                        {
                            button.IsSelected = true;
                        }
                    }
                    else
                    {
                        if (citem.IsSelected)
                        {
                            citem.IsSelected = false;
                        }
                    }
                    n++;
                }
                //
                BackgroundControl master = null;
                if (this.AutomaticLoadControlID != string.Empty)
                {
                    master = this.Parent.FindControl(this.AutomaticLoadControlID) as BackgroundControl;
                }
                //
                if (master == null)
                {
                    master = BackgroundControl.GetCurrent(this.Page);
                }
                //
                if (master != null)
                {
                    this.AutomaticLoadControl = master.AutomaticLoadControl;
                    //
                    if (button.IsDefaultMenu)
                    {
                        master.DefaultUpdateMenuAscx();
                    }
                    else if (button.IsMenuBack)
                    {
                        master.LoadParentMenu();
                    }
                    else
                    {
                        if (this.AutomaticLoadControl && button.Ascx != string.Empty && button.Ascx.EndsWith(".ascx", StringComparison.InvariantCultureIgnoreCase))
                        {
                            //验证加载的是否为菜单子控件。
                            if (button.IsMenu)
                                //加载菜单控件。
                                ((IUpdateMenu)master).LoadChildMenu(button.Ascx);
                            else
                                //加载内容控件。
                                master.UpdateAscx(button.Ascx);
                        }
                    }
                }
                this.OnCommand(new BackgroundCenterLeftMenuControlCommandEventArgs(button, button.CommandName, button.CommandArgument));
            }
        }
        #endregion
        BackgroundCenterLeftMenuButtonControlCollection _buttons;
        private Panel _end;
        private static readonly object _commandObject = new object();
        private static readonly object _actionObject = new object();

        /// <summary>
        /// 按钮点击事件。
        /// </summary>
        /// <remarks>按钮点击事件。</remarks>
        [Browsable(true)]
        public event CenterLeftMenuCommandEventHandler Command
        {
            add
            {
                Events.AddHandler(_commandObject, value);
            }
            remove
            {
                Events.RemoveHandler(_commandObject, value);
            }
        }
        /// <summary>
        /// 获取按钮集合。
        /// </summary>
        /// <remarks>获取按钮集合。</remarks>
        /// <value>WebControls.CenterLeftMenuButtonCollection</value>
        [
               PersistenceMode(PersistenceMode.InnerProperty),
               DesignerSerializationVisibility(DesignerSerializationVisibility.Visible),
               EditorAttribute(typeof(BackgroundCenterLeftMenuButtonControlCollectionEditor), typeof(UITypeEditor)),
               NotifyParentProperty(true)
               ]
        public BackgroundCenterLeftMenuButtonControlCollection Buttons
        {
            get
            {
                if (_buttons == null)
                {
                    _buttons = new BackgroundCenterLeftMenuButtonControlCollection();
                    if (IsTrackingViewState)
                    {
                        ((IStateManager)_buttons).TrackViewState();
                    }
                }
                return _buttons;
            }
        }

        /// <summary>
        /// 获取或设置自动加载控件对象。
        /// </summary>
        /// <remarks>获取或设置自动加载控件对象。</remarks>
        /// <value>string</value>
        [DefaultValue("")]
        [TypeConverter(typeof(ControlIDConverter))]
        [Browsable(true)]
        [Bindable(true)]
        [Category("Behavior")]
        [SRDescription("AutomaticLoadControlID", typeof(Properties.Resources))]
        public string AutomaticLoadControlID
        {
            get
            {
                object o = this.ViewState["AutomaticLoadControlID"];
                if (o == null) return string.Empty;
                return (string)o;
            }
            set
            {
                this.ViewState["AutomaticLoadControlID"] = value;
            }
        }

        /// <summary>
        /// 获取或设置是否自动加载菜单对应的控件。
        /// </summary>
        /// <remarks>获取或设置是否自动加载菜单对应的控件。</remarks>
        /// <value>bool</value>
        [DefaultValue(false)]
        [Browsable(true)]
        [Bindable(true)]
        [Category("Behavior")]
        [SRDescription("AutomaticLoadControl", typeof(Properties.Resources))]
        public bool AutomaticLoadControl
        {
            get
            {
                object o = this.ViewState["AutomaticLoadControl"];
                if (o == null) return false;
                return (bool)o;
            }
            set
            {
                this.ViewState["AutomaticLoadControl"] = value;
            }
        }

        /// <summary>
        /// 获取或设置按钮背景图片。
        /// </summary>
        /// <remarks>获取或设置按钮背景图片。</remarks>
        /// <value>string</value>
        [DefaultValue("")]
        [Editor(typeof(ImageUrlEditor), typeof(UITypeEditor))]
        [Browsable(true)]
        [Bindable(true)]
        [Category("Appearance")]
        [SRDescription("Manage_CenterLeftMenu_ButtonBackImage", typeof(Properties.Resources))]
        public string ButtonBackImage
        {
            get
            {
                object o = this.ViewState["ButtonBackImage"];
                if (o == null) return string.Empty;
                return (string)o;
            }
            set
            {
                this.ViewState["ButtonBackImage"] = value;
            }
        }

        /// <summary>
        /// 获取或设置按钮高度。
        /// </summary>
        /// <remarks>获取或设置按钮高度。</remarks>
        /// <value>System.Web.UI.WebControls.Unit</value>
        [DefaultValue(typeof(Unit), "26px")]
        [Browsable(true)]
        [Bindable(true)]
        [Category("Layout")]
        [TypeConverter(typeof(UnitConverter))]
        [SRDescription("Manage_CenterLeftMenu_ButtonHeight", typeof(Properties.Resources))]
        public virtual Unit ButtonHeight
        {
            get
            {
                object o = this.ViewState["ButtonHeight"];
                if (o == null)
                {
                    return Unit.Pixel(26);
                }
                else
                {
                    return (Unit)o;
                }
            }
            set
            {
                this.ViewState["ButtonHeight"] = value;
            }
        }

        /// <summary>
        /// 获取或设置按钮附加指令例。
        /// </summary>
        /// <remarks>获取或设置按钮附加指令例。</remarks>
        /// <value>string</value>
        [Themeable(false)]
        [Browsable(true)]
        [DefaultValue("")]
        [Category("Data")]
        [TypeConverter(typeof(DataFieldConverter))]
        [Bindable(false)]
        [SRDescription("DataCommandArgumentField", typeof(Properties.Resources))]
        public virtual string DataCommandArgumentField
        {
            get
            {
                object o = this.ViewState["DataCommandArgumentField"];
                if (o == null) return string.Empty;
                return (string)o;
            }
            set
            {
                this.ViewState["DataCommandArgumentField"] = value;
            }
        }

        /// <summary>
        /// 获取或设置按钮指令例。
        /// </summary>
        /// <remarks>获取或设置按钮指令例。</remarks>
        /// <value>string</value>
        [Themeable(false)]
        [Browsable(true)]
        [DefaultValue("")]
        [Category("Data")]
        [TypeConverter(typeof(DataFieldConverter))]
        [Bindable(false)]
        [SRDescription("DataCommandNameField", typeof(Properties.Resources))]
        public virtual string DataCommandNameField
        {
            get
            {
                object o = this.ViewState["DataCommandNameField"];
                if (o == null) return string.Empty;
                return (string)o;
            }
            set
            {
                this.ViewState["DataCommandNameField"] = value;
            }
        }

        /// <summary>
        /// 当数据源包含多个不同的数据项列表时，获取或设置数据绑定控件绑定到的数据列表的名称。
        /// </summary>
        /// <remarks>当数据源包含多个不同的数据项列表时，获取或设置数据绑定控件绑定到的数据列表的名称。</remarks>
        /// <value>string</value>
        [RefreshProperties(RefreshProperties.All)]
        [TypeConverter(typeof(DataMemberConverter))]
        [DefaultValue("")]
        [Bindable(false)]
        [Browsable(true)]
        [SRDescription("DataMember", typeof(Properties.Resources))]
        public override string DataMember
        {
            get
            {
                return base.DataMember;
            }
            set
            {
                if (base.DataMember != value)
                {
                    base.DataMember = value;
                    if (this.Initialized)
                    {
                        this.OnDataPropertyChanged();
                    }
                }
            }
        }
        /// <summary>
        /// 获取或设置按钮主键例。
        /// </summary>
        /// <remarks>获取或设置按钮主键例。</remarks>
        /// <value>string</value>
        [Themeable(false)]
        [Browsable(true)]
        [DefaultValue("")]
        [Category("Data")]
        [TypeConverter(typeof(DataFieldConverter))]
        [Bindable(false)]
        [SRDescription("DataValueField", typeof(Properties.Resources))]
        public string DataValueField
        {
            get
            {
                object o = this.ViewState["DataValueField"];
                if (o == null) return string.Empty;
                return (string)o;
            }
            set
            {
                this.ViewState["DataValueField"] = value;
            }
        }
        /// <summary>
        /// 获取或设置控件的 ID，数据绑定控件从该控件中检索其数据项列表。
        /// </summary>
        /// <remarks>获取或设置控件的 ID，数据绑定控件从该控件中检索其数据项列表。</remarks>
        /// <value>string</value>
        [RefreshProperties(RefreshProperties.Repaint)]
        [IDReferenceProperty(typeof(DataSourceControl))]
        [TypeConverter(typeof(DataSourceIDConverter))]
        [DefaultValue("")]
        [Bindable(false)]
        [Browsable(true)]
        [SRDescription("DataSourceID", typeof(Properties.Resources))]
        public override string DataSourceID
        {
            get
            {
                return base.DataSourceID;
            }
            set
            {
                if (string.IsNullOrEmpty(value))
                {
                    this.DataTextField = string.Empty;
                    this.DataCommandArgumentField = string.Empty;
                    this.DataCommandNameField = string.Empty;
                    this.DataMember = string.Empty;
                    this.DataValueField = string.Empty;
                    this.DataToolTipField = string.Empty;
                }
                if (base.DataSourceID != value)
                {
                    base.DataSourceID = value;
                    if (this.Initialized)
                    {
                        this.OnDataPropertyChanged();
                    }
                }
            }
        }

        /// <summary>
        /// 获取或设置对象，数据绑定控件从该对象中检索其数据项列表。
        /// </summary>
        /// <remarks>获取或设置对象，数据绑定控件从该对象中检索其数据项列表。</remarks>
        /// <value>object</value>
        [Browsable(false)]
        [Bindable(true)]
        [DefaultValue(null)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public override object DataSource
        {
            get
            {
                return base.DataSource;
            }
            set
            {
                if (base.DataSource != value)
                {
                    base.DataSource = value;
                    if (this.Initialized)
                    {
                        this.OnDataPropertyChanged();
                    }
                }
            }
        }

        /// <summary>
        /// 获取或设置按钮名称例。
        /// </summary>
        /// <remarks>获取或设置按钮名称例。</remarks>
        /// <value>string</value>
        [Themeable(false)]
        [Browsable(true)]
        [DefaultValue("")]
        [Category("Data")]
        [TypeConverter(typeof(DataFieldConverter))]
        [Bindable(false)]
        [SRDescription("DataTextField", typeof(Properties.Resources))]
        public virtual string DataTextField
        {
            get
            {
                object o = this.ViewState["DataTextField"];
                if (o == null) return string.Empty;
                return (string)o;
            }
            set
            {
                this.ViewState["DataTextField"] = value;
            }
        }

        /// <summary>
        /// 获取或设置当鼠标指针悬停在按钮上时显示的文本例。
        /// </summary>
        /// <remarks>获取或设置当鼠标指针悬停在按钮上时显示的文本例。</remarks>
        /// <value>string</value>
        [Themeable(false)]
        [Browsable(true)]
        [DefaultValue("")]
        [Category("Data")]
        [TypeConverter(typeof(DataFieldConverter))]
        [Bindable(false)]
        [SRDescription("DataToolTipField", typeof(Properties.Resources))]
        public virtual string DataToolTipField
        {
            get
            {
                object o = this.ViewState["DataFlagField"];
                if (o == null) return string.Empty;
                return (string)o;
            }
            set
            {
                this.ViewState["DataFlagField"] = value;
            }
        }

        /// <summary>
        /// 获取或设置选中按钮背景图片。
        /// </summary>
        /// <remarks>获取或设置选中按钮背景图片。</remarks>
        /// <value>string</value>
        [DefaultValue("")]
        [Editor(typeof(ImageUrlEditor), typeof(UITypeEditor))]
        [Browsable(true)]
        [Bindable(true)]
        [Category("Appearance")]
        [SRDescription("Manage_CenterLeftMenu_SelectedButtonBackImage", typeof(Properties.Resources))]
        public string SelectedButtonBackImage
        {
            get
            {
                object o = this.ViewState["SelectedButtonBackImage"];
                if (o == null) return string.Empty;
                return (string)o;
            }
            set
            {
                this.ViewState["SelectedButtonBackImage"] = value;
            }
        }

        /// <summary>
        /// 获取或设置是否显示底部对象。
        /// </summary>
        /// <remarks>获取或设置是否显示底部对象。</remarks>
        /// <value>bool</value>
        [DefaultValue(true)]
        [Browsable(true)]
        [Bindable(true)]
        [Category("Behavior")]
        [SRDescription("ShowEnd", typeof(Properties.Resources))]
        public bool ShowEnd
        {
            get
            {
                object o = this.ViewState["ShowEnd"];
                if (o == null) return true;
                return (bool)o;
            }
            set
            {
                this.ViewState["ShowEnd"] = value;
            }
        }

        /// <summary>
        /// </summary>
        protected override HtmlTextWriterTag TagKey
        {
            get
            {
                return HtmlTextWriterTag.Div;
            }
        }

        /// <summary>
        /// </summary>
        protected override string TagName
        {
            get
            {
                return "div";
            }
        }

        /// <summary>
        /// 获取或设置尾部高度。
        /// </summary>
        /// <remarks>获取或设置尾部高度。</remarks>
        /// <value>System.Web.UI.WebControls.Unit</value>
        [Bindable(true)]
        [DefaultValue(typeof(Unit), "6px")]
        [SRDescription("EndHeight", typeof(Properties.Resources))]
        [Browsable(true)]
        [Category("Layout")]
        [TypeConverter(typeof(UnitConverter))]
        public Unit EndHeight
        {
            get
            {
                object o = this.ViewState["EndHeight"];
                if (o == null) return Unit.Pixel(6);
                return (Unit)o;
            }
            set
            {
                this.ViewState["EndHeight"] = value;
            }
        }

        /// <summary>
        /// 获取菜单底部对象。
        /// </summary>
        /// <remarks>获取菜单底部对象。</remarks>
        /// <value>System.Web.UI.WebControls.Panel</value>
        [Browsable(false)]
        public Panel End
        {
            get
            {
                return _end;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        protected override void TrackViewState()
        {
            base.TrackViewState();
            if (this._buttons != null)
            {
                ((IStateManager)this._buttons).TrackViewState();
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        protected override object SaveViewState()
        {
            return new Pair(base.SaveViewState(), this._buttons == null ? null : ((IStateManager)this._buttons).SaveViewState());
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="state"></param>
        protected override void LoadViewState(object state)
        {
            Pair pair = state as Pair;
            if (pair != null)
            {
                base.LoadViewState(pair.First);
                if (pair.Second != null)
                {
                    ((IStateManager)this.Buttons).LoadViewState(pair.Second);
                }
            }
        }

        /// <summary>
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
        }

        /// <summary>
        /// </summary>
        /// <param name="data"></param>
        protected override void PerformDataBinding(System.Collections.IEnumerable data)
        {
            if (data == null || string.IsNullOrEmpty(this.DataSourceID))
                return;
            this.Buttons.Clear();
            //键值
            string _DataTextField = this.DataTextField;
            string _DataCommandArgumentField = this.DataCommandArgumentField;
            string _DataCommandNameField = this.DataCommandNameField;
            string _DataToolTipField = this.DataToolTipField;
            string _DataPrimaryKeyField = this.DataValueField;
            //
            foreach (object dataItem in data)
            {
                foreach (object cdataItem in data)
                {
                    BackgroundCenterLeftMenuButtonControl b = new BackgroundCenterLeftMenuButtonControl();
                    if (!string.IsNullOrEmpty(_DataTextField))
                    {
                        b.Text = DataBinder.GetPropertyValue(cdataItem, _DataTextField, null);
                    }
                    //
                    if (!string.IsNullOrEmpty(_DataCommandArgumentField))
                    {
                        b.CommandArgument = DataBinder.GetPropertyValue(cdataItem, _DataCommandArgumentField, null);
                    }
                    //
                    if (!string.IsNullOrEmpty(_DataCommandNameField))
                    {
                        b.CommandName = DataBinder.GetPropertyValue(cdataItem, _DataCommandNameField, null);
                    }
                    //
                    if (!string.IsNullOrEmpty(_DataToolTipField))
                    {
                        b.ToolTip = DataBinder.GetPropertyValue(cdataItem, _DataToolTipField, null);
                    }
                    this.Buttons.Add(b);
                }
            }
            base.ChildControlsCreated = false;
            this.EnsureChildControls();
        }

        /// <summary>
        /// </summary>
        /// <param name="writer"></param>
        protected override void Render(HtmlTextWriter writer)
        {
            if (this.DesignMode)
            {
                this.EnsureChildControls();
            }
            else
            {
                this.Style["font-size"] = "0px";
                this.Style["height"] = "auto";
                this.Style["overflow"] = "hidden";
                int b = 0;
                foreach (BackgroundCenterLeftMenuButtonControl citem in this.Buttons)
                {
                    ((ICompositeControlDesignerAccessor)citem).RecreateChildControls();
                    citem.Button.Attributes["href"] = "javascript:__doPostBack('" + this.UniqueID + "','Button&" + b.ToString() + "')";
                    Page.ClientScript.RegisterForEventValidation(this.UniqueID, "Button&" + b.ToString());
                    b++;
                    //
                    citem.Style["overflow"] = "hidden";
                    citem.Style["background-position"] = "left top";
                    citem.Style["white-space"] = "nowrap";
                    citem.Style["text-overflow"] = "ellipsis";
                    citem.Height = this.ButtonHeight;
                    citem.Width = this.Width;
                    if (citem.IsSelected)
                        if (string.IsNullOrEmpty(this.SelectedButtonBackImage))
                            citem.Style["background-image"] = "url(" + this.ResolveClientUrl(this.GetWebResourceUrl("SelectedButtonBg.gif")) + ")";
                        else
                            citem.Style["background-image"] = "url(" + this.ResolveClientUrl(this.SelectedButtonBackImage) + ")";
                    else
                        if (string.IsNullOrEmpty(this.ButtonBackImage))
                            citem.Style["background-image"] = "url(" + this.ResolveClientUrl(this.GetWebResourceUrl("ButtonBg.gif")) + ")";
                        else
                            citem.Style["background-image"] = "url(" + this.ResolveClientUrl(this.ButtonBackImage) + ")";
                    //
                    citem.ButtonContainer.Height = this.ButtonHeight;
                    citem.ButtonContainer.Width = this.Width;
                    citem.ButtonContainer.Style["overflow"] = "hidden";
                    citem.ButtonContainer.Style["font-size"] = "0px";
                    citem.ButtonContainer.Style["padding-top"] = "5px";
                    citem.ButtonContainer.Style["padding-left"] = "4px";
                    //
                    citem.Button.Style["font-size"] = "12px";

                }
                //
                if (this.ShowEnd)
                {
                    this._end.Visible = true;
                    this._end.Style["background-position"] = "left top";
                    this._end.Width = this.Width;
                    this._end.Height = this.EndHeight;
                    this._end.Style["background-image"] = "url(" + this.ResolveClientUrl(this.GetWebResourceUrl("EndBg.gif")) + ")";
                }
                else
                {
                    this._end.Visible = false;
                }
            }
            if (Page != null)
                Page.VerifyRenderingInServerForm(this);
            base.Render(writer);
        }

        /// <summary>
        /// 设计时获取资源文件地址。
        /// </summary>
        /// <remarks>设计时获取资源文件地址。</remarks>
        /// <returns>string</returns>
        internal virtual string GetWebResourceUrl(string resourceUrl)
        {
            return this.Page.ClientScript.GetWebResourceUrl(typeof(BackgroundCenterLeftMenuControl), "GSC.WebControls.BackgroundCenterLeftMenuControl.Images." + resourceUrl);
        }

        /// <summary>
        /// </summary>
        /// <param name="e"></param>
        protected override void OnInit(EventArgs e)
        {
            Page.RegisterRequiresControlState(this);
            base.OnInit(e);
            if (this.AutomaticLoadControlID != string.Empty && this.AutomaticLoadControl)
            {
                Control control = this.Parent.FindControl(this.AutomaticLoadControlID);
                if (control is IUpdateAscx)
                {
                    ((IUpdateAscx)control).UpdateAscx();
                }
            }
        }

        /// <summary>
        /// 按钮点击事件。
        /// </summary>
        /// <remarks>按钮点击事件。</remarks>
        /// <param name="e"></param>
        protected virtual void OnCommand(BackgroundCenterLeftMenuControlCommandEventArgs e)
        {
            CenterLeftMenuCommandEventHandler handler = (CenterLeftMenuCommandEventHandler)Events[_commandObject];
            if (handler != null)
            {
                handler(this, e);
            }
        }

        /// <summary>
        /// </summary>
        protected virtual void CreateControlHierarchy()
        {
            foreach (BackgroundCenterLeftMenuButtonControl item in this.Buttons)
            {
                Controls.Add(item);
            }
            //
            this._end = new Panel();
            this._end.ID = "End";
            Controls.Add(_end);
        }

        /// <summary>
        /// </summary>
        protected override void CreateChildControls()
        {
            Controls.Clear();
            CreateControlHierarchy();
            ClearChildViewState();
        }

        /// <summary>
        /// </summary>
        /// <param name="obj"></param>
        protected override void AddParsedSubObject(object obj)
        {
            if (obj is BackgroundCenterLeftMenuButtonControl)
                this.Buttons.Add((BackgroundCenterLeftMenuButtonControl)obj);
        }

        /// <summary>
        /// 获取选中的内容。
        /// </summary>
        /// <remarks>获取选中的内容。</remarks>
        /// <value>string</value>
        [Browsable(false)]
        public string SelectedText
        {
            get
            {
                object o = this.ViewState["SelectedText"];
                if (o == null) return string.Empty;
                return (string)o;
            }
        }

        /// <summary>
        /// 获取选中的值。
        /// </summary>
        /// <remarks>获取选中的值。</remarks>
        /// <value>int</value>
        [Browsable(false)]
        public int SelectedValue
        {
            get
            {
                object o = this.ViewState["SelectedValue"];
                if (o == null) return -1;
                return (int)o;
            }
        }
        /// <summary>
        /// 重置默认按钮状态。
        /// </summary>
        /// <remarks>重置默认按钮状态。</remarks>
        public void ResetDefault()
        {
            foreach (BackgroundCenterLeftMenuButtonControl item in this.Buttons)
            {
                item.IsSelected = false;
            }
        }
    }
}